import { getUserInfo } from '../../../model/service/account/userInfo';
import { pick } from 'lodash';

export default async function getAccountInfo(ctx: Context, next: Next): Promise<void> {
  const { body } = ctx.request;
  const { filter, condition }  = body;

  if (filter && !Array.isArray(filter)) {
    ctx.api.fail(-1, 'filter必须为数组');
  }
  const data = await getUserInfo(condition);
  
  // 返回指定属性
  const result = filter ? pick(data[0], filter) : data[0];

  ctx.api.success(result, 'sucess');

  return next();
}